<?php
session_start();
include 'dbconnect.php';

  // Check connection
if (mysqli_connect_errno())
  {
  //echo "alert'Failed to connect to MySQL: ' . mysqli_connect_error()";
  }
$number = $_SESSION['number'];
if ($number[0] == "+")
	$number[0] = "_";
$table = "SELECT * FROM activity".$number." order by timestamp DESC;";
$result = mysqli_query($con, $table);
$count = 0;
$html = "";
$html .= "<div></div>";
while($row = mysqli_fetch_array($result))
  {
	$mil = $row['timestamp'];
	$seconds = $mil / 1000;
	$date = date("D, d M Y, H:i:s", $seconds);

  if ($row['activityId'] == '0')
	continue;
  
  if ($row['seen']=='0' ){
	$count = $count + 1;
	$html .= "<li class='new' onclick='update($row[id], $row[contactId], $row[data])' id='".$row['id']."'>".
				"<div class='woogie-activity-item'>".
			 "<div class='woogie-activity-name'><div class='woogie-activity-name-left'>".$row['name'].
				"</div><div class='woogie-activity-name-right'><img src='images/new.png'/></div></div>";
  }
  else{
	$html .= "<li class='old' onclick='update($row[id], $row[contactId], $row[data])' id='".$row['id']."'>".
				"<div class='woogie-activity-item'>".
			 "<div class='woogie-activity-name'><div class='woogie-activity-name-left'>".$row['name'].
				"</div><div class='woogie-activity-name-right'><img src='images/old.png'/></div></div>";
  }
	$html .= "<div class='woogie-activity-data'><br/>".$row['data']."</div>";
	
	$html .= "<div class='woogie-activity-time'>".$date."</div>".
			 "</div>".
			 "</li>";
  }
  echo "<p class='notif' id='notif'>".$count."</p>%".$html;
mysqli_close($con);

?>
